package com.zuihai.app.mvp.ui.widget;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.lcodecore.tkrefreshlayout.IHeaderView;
import com.lcodecore.tkrefreshlayout.OnAnimEndListener;
import com.zuihai.app.R;

/**
 * Created by Administrator on 2017/5/22 0022.
 */

public class SimpleRefresh extends FrameLayout implements IHeaderView {

    private GifView mGifView;
    private TextView mHintView;

    public SimpleRefresh(@NonNull Context context) {
        this(context, null);
    }

    public SimpleRefresh(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleRefresh(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        View refresh = LayoutInflater.from(getContext()).inflate(R.layout.layout_refresh, null, false);
        mGifView = (GifView) refresh.findViewById(R.id.gif_view);
        mHintView = (TextView) refresh.findViewById(R.id.tv_hint);
        addView(refresh);
    }

    @Override
    public View getView() {
        return this;
    }

    public GifView getGifView(){
        return mGifView;
    }

    @Override
    public void onPullingDown(float fraction, float maxHeadHeight, float headHeight) {
        mGifView.pause();
        /*mHintView.setText("下拉发现秘密");
        if (fraction > 0.8){
            mHintView.setText("放开发现秘密");
        }*/
    }

    @Override
    public void onPullReleasing(float fraction, float maxHeadHeight, float headHeight) {
      //  mHintView.setText("正在发现");
    }

    @Override
    public void startAnim(float maxHeadHeight, float headHeight) {
        mGifView.play();
        //mHintView.setText("正在发现");
    }

    @Override
    public void onFinish(OnAnimEndListener animEndListener) {
        animEndListener.onAnimEnd();
    }

    @Override
    public void reset() {
        mGifView.pause();
       // mHintView.setText("发现秘密");
    }
}
